package org.spp.voronoi;

import java.util.ArrayList;
import java.util.List;

/**
 * BoundedRegion.java
 * @author Ilio Catallo, Eleonora Ciceri
 * @version 1.0
 * 
 * Description: the class implements the bounded region that contains all the
 *              objects of the data set
 * 
 * Date: Jul 10, 2011
 */
public class BoundedRegion {
    
    // Attributes
    private List<Facet> facets;
    
    /**
     * Constructor of the class BoundedRegion
     */
    public BoundedRegion() {
        this.facets = new ArrayList<Facet>();
    }
    
    /**
     * Constructor of the class BoundedRegion
     * @param type 
     */
    public BoundedRegion(String type) {
        this();
        
        if (type.equals("3D"))
            buildCube();
        else
            buildSquare();
    }
    
    /**
     * Constructor of the class BoundedRegion
     * @param facets 
     */
    public BoundedRegion(List<Facet> facets) {
        this();        
        this.facets.addAll(facets);
    }
    
    /**
     * Method for the retrieve of the facets of the bounded region
     * @return facets
     */
    public List<Facet> getFacets() {
        return facets;
    }
    
    /**
     * Method that shapes the bounded region as a cube 
     */
    private void buildCube() {
        facets.add(new Plane(1.0, 0.0, 0.0, 0.5, true));
        facets.add(new Plane(-1.0, 0.0, 0.0, 0.5, true));
        facets.add(new Plane(0.0, 1.0, 0.0, 0.5, true));
        facets.add(new Plane(0.0, -1.0, 0.0, 0.5, true));
        facets.add(new Plane(0.0, 0.0, 1.0, 0.5, true));
        facets.add(new Plane(0.0, 0.0, -1.0, 0.5, true));  
    }
    
    /**
     * Method that shapes the bounded region as a square
     */
    private void buildSquare() {
        facets.add(new Line(1.0, 0.0, 0.5, true));
        facets.add(new Line(-1.0, 0.0, 0.5, true));
        facets.add(new Line(0.0, 1.0, 0.5, true));
        facets.add(new Line(0.0, -1.0, 0.5, true));
    }
}
